<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Hello, World</title>
    <style type="text/css">
        html {
            height: 100%
        }

        body {
            height: 100%;
            margin: 0px;
            padding: 0px
        }

        #container {
            height: 600px;
            width: 600px;
        }
    </style>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=xjrsZ0yp82fAm3lFdhINLxRdBdBUNTqr">
//v3.0版本的引用方式：src="http://api.map.baidu.com/api?v=3.0&ak=您的密钥"
    </script>
</head>

<body>
    <div id="container"></div>
    <script type="text/javascript"> 
        var map = new BMap.Map("container");
        // 创建地图实例  
        var point = new BMap.Point(116.404, 39.915);
        // 创建点坐标  
        map.centerAndZoom(point, 15);
        map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放

        // 事件
        map.addEventListener("click", function (e) {
            _addOverlay(e.point)
        });


        function _deletePoint() {
            map.clearOverlays();
        }


        function _addOverlay(position) {
            _deletePoint()
            var mk = new BMap.Marker(position);
            map.addOverlay(mk);
            map.panTo(position);//r.point
            mk.enableDragging();
            mk.addEventListener("dragend", function (e) {
                alert("当前位置：" + e.point.lng + ", " + e.point.lat);
            })
        }

        // 定位
        var geolocation = new BMap.Geolocation();
        geolocation.getCurrentPosition(function (r) {
            if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                _addOverlay(r.point)
                // alert('您的位置：' + r.point.lng + ',' + r.point.lat);
            }
            else {
                alert('failed' + this.getStatus());
            }
        });

    </script>
</body>

</html>